using Cysharp.Threading.Tasks;
using MoonFramework.Scripts.Scences;
using MoonFramework.Scripts.View.UI;
using MoonFramework.Template;
using Tool;
using UI;
using UnityEngine;

public enum CursorState
{
    Normal = 0,
    Handle = 1
}

public class GameManger : BaseGameMono<GameManger>
{
    public void Start()
    {
        Init();
    }

    private void Init()
    {
        SetCursorState(CursorState.Normal);
    }

    #region 鼠标指针

    private CursorState _cursorState = CursorState.Normal;
    [SerializeField] private Texture2D[] cursorTexture2Ds;

    public void SetCursorState(CursorState cursorState)
    {
        if (cursorState == _cursorState) return;
        _cursorState = cursorState;
        var tex = cursorTexture2Ds[(int)cursorState];
        Cursor.SetCursor(tex, Vector2.zero, CursorMode.Auto);
    }

    #endregion

    #region 跨场景

    /// <summary>
    ///     创建新存档进入游戏
    /// </summary>
    public void CreateNewArchive_EntryGame(int mapSize, int mapSeed, int spawnSeed, float marshLimit)
    {
        //初始化存档
        ArchiveManager.Instance.CreateNewArchive(mapSize, mapSeed, spawnSeed, marshLimit);
        //加载场景
        ScenesManager.Instance.LoadSceneAsync("GameScene").Forget();
        GameSceneManager.Instance.StartGame().Forget();
    }

    /// <summary>
    ///     使用当前存档进入游戏
    /// </summary>
    public void UseCurArchive_EntryGame()
    {
        ArchiveManager.Instance.LoadCurArchive().Forget();
        //加载场景
        ScenesManager.Instance.LoadSceneAsync("GameScene").Forget();
        GameSceneManager.Instance.StartGame().Forget();
    }

    /// <summary>
    /// 返回菜单场景
    /// </summary>
    public async void EnterMenu()
    {
        //加载场景
        var window = UIManager.Instance.Show<UI_GameLoadWindow>();
        float f = 0;
        ScenesManager.Instance.LoadSceneAsync("MenuScene", ()=>
        {
            window.UpdateProgress(100);
            UIManager.Instance.Close<UI_GameLoadWindow>();
        }).Forget();
        while (window.gameObject.activeSelf)
        {
            await UniTask.Yield();
            f += 10;
            window.UpdateProgress(f);
        }
    }

    #endregion
}